package dq.study.shiro.encrypt;


import org.apache.shiro.codec.Base64;
import org.apache.shiro.codec.Hex;

/**
 * 编解码
 * @author dongqun
 * @date 2020/4/13 13:30
 */
public class EncodeDecode {

    public static String encode(String str){
        return Base64.encodeToString(str.getBytes());
    }

    public static String decode(String str){
        return Base64.decodeToString(str);
    }


    public static void main(String[] args){
        String var = "hello";
        String en = encode(var);
        System.out.println(en);
        String de = decode(en);
        System.out.println(de);
        System.out.println(var.equals(de));

        String str = "hello";
        String base64Encoded = Hex.encodeToString(str.getBytes());
        System.out.println(base64Encoded);
        String str2 = new String(Hex.decode(base64Encoded.getBytes()));
        System.out.println(str.equals(str2));
    }
}
